package com.songtech.cmdrecord.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.songtech.cmdrecord.dao.CmdRecordMapper;
import com.songtech.cmdrecord.service.CmdRecordService;
import com.songtech.server.constant.enumConstant.CmdEnum;
import com.songtech.web.entry.SysPosTerminalHistory;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:  上下行命令信息service实现
 *
 * @Author: rentie
 * @Date: 2018/4/12 10:38
 **/
@Service
public class CmdRecordServiceImpl implements CmdRecordService {

    @Resource
    private CmdRecordMapper cmdRecordMapper;


    @Override
    public PageInfo<SysPosTerminalHistory> queryComdRecord(String imei, Integer sender,Integer currentPage, Integer pageSize) throws Exception {
        //禁用合理化，如果pageNum<1或pageNum>pages会返回空数据
        PageHelper.startPage(currentPage, pageSize,true,false);
        List<SysPosTerminalHistory> list = cmdRecordMapper.queryComdRecord(imei,sender);
        if (CollectionUtils.isNotEmpty(list)){
            for (SysPosTerminalHistory bean: list) {
                bean.setCmdMessage(CmdEnum.queryMessage(bean.getCmdType()));
            }
        }
        return new PageInfo<SysPosTerminalHistory>(list);
    }
}
